package com.gaojice.ftp.server;

import java.net.InetAddress;
import java.net.NetworkInterface;
import java.util.Enumeration;

import jftp.FtpServer;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class AndroidFtpServer extends Activity {

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);
		TextView textView = (TextView) findViewById(R.id.tv);

		Enumeration<NetworkInterface> netInterfaces = null;
		try {
			netInterfaces = NetworkInterface.getNetworkInterfaces();
			while (netInterfaces.hasMoreElements()) {
				NetworkInterface ni = netInterfaces.nextElement();
				textView.append("\nDisplayName:" + ni.getDisplayName() + "\n");
				textView.append("Name:" + ni.getName() + "\n");
				Enumeration<InetAddress> ips = ni.getInetAddresses();
				while (ips.hasMoreElements()) {
					textView.append("IP:"

					+ ips.nextElement().getHostAddress() + "\n");
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		textView.append("\nPort: " + FtpServer.FTP_PORT);

		Button startbtn = (Button) findViewById(R.id.btn_start);
		Button stopbtn = (Button) findViewById(R.id.btn_stop);
		startbtn.setOnClickListener(new OnClickListener() {

			public void onClick(View arg0) {
				Intent serviceIntent = new Intent();
				serviceIntent.setAction("com.gaojice.intent.filter.FtpService");
				startService(serviceIntent);

			}
		});
		stopbtn.setOnClickListener(new OnClickListener() {
			public void onClick(View arg0) {
				Intent serviceIntent = new Intent();
				serviceIntent.setAction("com.gaojice.intent.filter.FtpService");
				stopService(serviceIntent);
			}
		});

	}

}